$(document).ready(function(){
	init(1);
	
	/*JQuery 限制文本框只能输入数字 */
  $("#goPage").keyup(function (){
        $(this).val($(this).val().replace( /\D|^0/g, ''));
   }).bind("paste", function(){ //CTR+V事件处理
        $(this).val($(this).val().replace( /\D|^0/g, ''));
   }).css("ime-mode", "disabled"); //CSS设置输入法不可用

});

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//列表显示
function init(currentPage){
	var terId = $("#terId").val();
	var stuId = $("#stuId").val();
	var subClassType = $("#subClassType").val();
//	var claId = $("#claId").val();
	var path = $("#path").val()+"/OtherCheaperList.action";
	var pageSize = 10;
	var pageCount = "";
	 
//	if(claId == 0 && trim(stuname).length <= 0){
//		$("#divshow").show();$("#divload,#page").hide();
//		$("#myTable").append("<tr><td colspan='12'>没有匹配的数据！</td></tr>");
//	}else{
	   	$.ajax({
		      type: "post",
		      url: path,
		      dataType: "json",
		      data: "currentPage="+currentPage
	          +"&pageSize="+pageSize
	          +"&terId="+terId
	          +"&stuId="+stuId
	           +"&subClassType="+subClassType,
//	          +"&claId="+claId,
	         
		      cache: false, //默认为true,设为false将不缓存页面，开发时使用。正式使用时可注释掉。
		      beforeSend: function(){$("#divload").show();$("#divshow,#page").hide();},
		      complete: function(){$("#divshow,#page").show();$("#divload").hide();},
		      success: function(json){
		    	
		    	  $("#myTable tr:gt(0)").remove();//移除Id为result的表格里的行，从第二行开始
		    	  //总记录数
		    	  pageCount = json[0].pageCount;
		    	  if(pageCount != 0){
	    			 for(var i = 0; i < json.length; i++){
		    			 $("#dataShow").append("<tr>"+
				          "<td>"+json[i].stuName+"</td>"+
				          "<td>"+json[i].subjectName+"</td>"+
				          "<td>"+json[i].coupon+"</td>"+
				          "<td>"+json[i].voncher+"</td>"+
				          "<td>"+json[i].scholarship+"</td>"+
//				          "<td>"+json[i].teaName+"</td>"+
//				          "<td>"+json[i].desc+"</td>"+
				        "</tr>");
	    			 }
	      		  }else{
	      			 $("#dataShow").append("<tr><td colspan='5'>无记录！</td></tr>");
		    	  }
			    	  
		    	  //行交替颜色
		    	  $("#myTable tr:even").css("background-color","#f5f5f5");
			  		$("#myTable tr").live("mouseenter",function(){
			  			$(this).addClass("lightbluebg");
			  		}).live("mouseleave",function(){
			  			$(this).removeClass("lightbluebg");
			  	  });
	    	  
		    	  //漂亮的提示 哈哈
//		    	  $('.skyblue').poshytip({
//		    			className: 'tip-skyblue',
//		    			bgImageFrameSize: 9,
//		    			offsetX: 0,
//		    			offsetY: 20
//		    	  });
			    	  
		    	    //设定分页
		    	    $("#totalRows").html(pageCount);//总记录数
		    	    $("#currentPage").html(currentPage);//当前页数
		    	    $("#pageSize").html(pageSize); //每页显示记录数
		    	    
		    	    var totalPageNum = 0;
		    	    if((pageCount % pageSize) == 0){
			    	     $("#totalPages").html(pageCount / pageSize);
			    	     totalPageNum = pageCount / pageSize;
		    	    }else{
			    	     $("#totalPages").html(parseInt(pageCount / pageSize) + 1);
			    	     totalPageNum = parseInt(pageCount / pageSize) + 1;
		    	    }
		    	    $("#totalPge").val(totalPageNum); //将总页数赋值给totalPge隐藏域
		    	    
		    	    //设定上一页，下一页  首页、尾页的链接
		    	    if(pageCount <= pageSize){
		    	    	 $("#first").attr("href","javascript:void(0);");
		    	    	 $("#previous").attr("href","javascript:void(0);");
		    	    	 $("#next").attr("href","javascript:void(0);");
		    	    	 $("#last").attr("href","javascript:void(0);");
		    	    	 $("#go").removeAttr("onclick");
		    	    }else if(currentPage == 1){
		    	    	 $("#first").attr("href","javascript:void(0);");
		    	    	 $("#previous").attr("href","javascript:void(0);");
		    	    	 $("#next").attr("href","javascript:init("+(currentPage+1)+");");
		    	    	 $("#last").attr("href","javascript:init("+totalPageNum+");");
		    	    }else if(currentPage == totalPageNum){
		    	    	 $("#first").attr("href","javascript:init(1);");
		    	    	 $("#previous").attr("href","javascript:init("+(currentPage-1)+");");
		    	    	 $("#next").attr("href","javascript:void(0);");
		    	    	 $("#last").attr("href","javascript:void(0);");
		    	    }else{
		    	    	 $("#first").attr("href","javascript:init(1);");
		    	    	 $("#previous").attr("href","javascript:init("+(currentPage-1)+");");
		    	    	 $("#next").attr("href","javascript:init("+(currentPage+1)+");");
		    	    	 $("#last").attr("href","javascript:init("+totalPageNum+");");
		    	    }
		      }//success END
		}); //ajax  END
//	}
}//列表结束

//输入页数跳转页面
function goOnclick(){
	var pageNum = $("#goPage").val();
	var totalPge = $("#totalPge").val();
	if(pageNum != "" && parseInt(pageNum) <= parseInt(totalPge)){
		init(pageNum);
	}else{
		$.dialog.tips('请输入总页数以内的整数！',3,'alert.gif');
	}
}
